define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            console.log('888');
            Template.helper("Fast", Fast);

            //因为日期选择框不会触发change事件，导致无法刷新textarea，所以加上判断
            $(document).on("dp.change", "#second-form .datetimepicker", function () {
                $(this).parent().prev().find("input").trigger("change");
            });
            $(document).on("fa.event.appendfieldlist", "#first-table .btn-append", function (e, obj) {

            });
            $(document).on("fa.event.appendfieldlist", "#second-table .btn-append", function (e, obj) {
                //绑定动态下拉组件
                Form.events.selectpage(obj);
                //绑定日期组件
                Form.events.datetimepicker(obj);
                //绑定上传组件
                Form.events.faupload(obj);

                //上传成功回调事件，变更按钮的背景
                $(".upload-image", obj).data("upload-success", function (data) {
                    $(this).css("background-image", "url('" + Fast.api.cdnurl(data.url) + "')");
                });
            });
            $("#c-shop_id").data("params", function (obj) {
                return  {custom: {country_id: $("#c-country_id").val()}} ;
            });

            $("#c-goodssku_id").data("params", function (obj) {
                return  {custom: {country_id: $("#c-country_id").val()}} ;
            });

            $(document).on("change", "#c-goodssku_id", function(obj){
                let id = $("#c-goodssku_id").val();
                console.log(id);
                //后续操作
                $.post(
                    'goodssku/getSku',{id:id},function (data){
                        console.log('changeing!!!');
                        console.log(data.data.goods_sku);
                        $("#c-cost").val(data.data.cost);
                        $("#c-china_extra").val(data.data.export_extra_fee);
                        $("#c-oversea_extra").val(data.data.oversea_extra_fee);
                        $("#c-trade_commission_rate").val(data.data.trade_commission_rate);
                        $("#c-tk_handling_rate").val(data.data.tk_handling_rate);
                        $("#c-tk_handling_fee").val(data.data.tk_handling_fee);
                        $("#c-sfp_rate").val(data.data.sfp_rate);
                        $("#c-alliance_commission_rate").val(data.data.alliance_commission_rate);
                        $("#c-super_coupon_rate").val(data.data.super_coupon_rate);
                        $("#c-bonus_cash_rate").val(data.data.bonus_cash_rate);
                        $("#c-tariff_rate").val(data.data.tariff_rate);
                        $("#c-value_added_rate").val(data.data.value_added_rate);
                        $("#c-export_transport_fee").val(data.data.export_transport_fee);
                        $("#c-oversea_order_export_rate").val(data.data.oversea_order_export_rate);
                        $("#c-oversea_order_pack_rate").val(data.data.oversea_order_pack_rate);
                        $("#c-oversea_order_xujian_fee").val(data.data.oversea_order_xujian_fee);
                    }
                );
            });

            Form.api.bindevent($("form[role=form]"), function (data, ret) {
                console.log(data);
                layer.msg(data.message);
/*                layer.open({
                    type: 2,
                    title: 'iframe父子操作',
                    maxmin: true,
                    shadeClose: true, //点击遮罩关闭层
                    area : ['800px' , '520px'],
                    content: data.message
                });*/
            });
        },

        add: function () {
            Controller.api.bindevent();
            console.log('999');
        },
        api: {
            bindevent: function () {
                console.log('111');
                Form.api.bindevent($("form[role=form]"));
                console.log('7777');


            }
        }
    };
    return Controller;
});
